﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;


    public class THONGOTINXE_DATAACCESS
    {
        private static string sp_Name = "SP_XETOTAL";
        public static void ExcuteQueryString(string ACTION, XE_ENTITY xeEntity)
        {
            
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            try
            {
                 
                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("ACTION", ACTION);
                if (xeEntity != null)
                {
                     com.Parameters.AddWithValue("MAXE", xeEntity.MAXE);
                    com.Parameters.AddWithValue("TENXE", xeEntity.TENXE);
                    com.Parameters.AddWithValue("MAHANG", xeEntity.MAHANG);
                    com.Parameters.AddWithValue("XUATXU", xeEntity.XUATXU);
                    com.Parameters.AddWithValue("MAUSAC", xeEntity.MAUSAC);
                    com.Parameters.AddWithValue("NHIENLIEU", xeEntity.NHIENLIEU);

                    com.Parameters.AddWithValue("SOCHO", xeEntity.SOCHO);
                    com.Parameters.AddWithValue("SOCUA", xeEntity.SOCUA);
                    com.Parameters.AddWithValue("HOPSO", xeEntity.HOPSO);
                    com.Parameters.AddWithValue("HETHONGPHANH", xeEntity.HETHONGPHANH);
                    com.Parameters.AddWithValue("DONGCO", xeEntity.DONGCO);
                    com.Parameters.AddWithValue("DUNGTICHXILANH", xeEntity.DUNGTICHXILANH);

                    com.Parameters.AddWithValue("DUNGTICHBINHNHIENLIEU", xeEntity.DUNGTICHBINHNHIENLIEU);
                    com.Parameters.AddWithValue("TRONGLUONG", xeEntity.TRONGLUONG);
                    com.Parameters.AddWithValue("THIETBIDINHVI", xeEntity.THIETBIDINHVI);
                    com.Parameters.AddWithValue("TAYLAITROLUC", xeEntity.TAYLAITROLUC);
                    com.Parameters.AddWithValue("DIEUHOA", xeEntity.DIEUHOA);
                    com.Parameters.AddWithValue("THIETBIGIAITRI", xeEntity.THIETBIGIAITRI);

                    com.Parameters.AddWithValue("TUIKHIANTOAN", xeEntity.TUIKHIANTOAN);
                    com.Parameters.AddWithValue("HETHONGBAOTROM", xeEntity.HETHONGBAOTROM);
                    com.Parameters.AddWithValue("CHONGBOCUNGPHANH", xeEntity.CHONGBOCUNGPHANH);
                    com.Parameters.AddWithValue("DIEUKHIENHANHTRINH", xeEntity.DIEUKHIENHANHTRINH);
                    com.Parameters.AddWithValue("GIABAN", xeEntity.GIABAN);


                    com.Parameters.AddWithValue("HINHANH", xeEntity.HINH);
         

                  
                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
       
        public static DataSet GETDATATABLE(string ACTION, XE_ENTITY xeEntity)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (xeEntity != null)
                {
                    com.Parameters.AddWithValue("@MAXE", xeEntity.MAXE);
                    com.Parameters.AddWithValue("@TENXE", xeEntity.TENXE);
                    com.Parameters.AddWithValue("@MAHANG", xeEntity.MAHANG);
                    com.Parameters.AddWithValue("@XUATXU", xeEntity.XUATXU);
                    com.Parameters.AddWithValue("@MAUSAC", xeEntity.MAUSAC);
                    com.Parameters.AddWithValue("@NHIENLIEU", xeEntity.NHIENLIEU);

                    com.Parameters.AddWithValue("@SOCHO", xeEntity.SOCHO);
                    com.Parameters.AddWithValue("@SOCUA", xeEntity.SOCUA);
                    com.Parameters.AddWithValue("@HOPSO", xeEntity.HOPSO);
                    com.Parameters.AddWithValue("@HETHONGPHANH", xeEntity.HETHONGPHANH);
                    com.Parameters.AddWithValue("@DONGCO", xeEntity.DONGCO);
                    com.Parameters.AddWithValue("@DUNGTICHXILANH", xeEntity.DUNGTICHXILANH);

                    com.Parameters.AddWithValue("@DUNGTICHBINHNHIENLIEU", xeEntity.DUNGTICHBINHNHIENLIEU);
                    com.Parameters.AddWithValue("@TRONGLUONG", xeEntity.TRONGLUONG);
                    com.Parameters.AddWithValue("@THIETBIDINHVI", xeEntity.THIETBIDINHVI);
                    com.Parameters.AddWithValue("@TAYLAITROLUC", xeEntity.TAYLAITROLUC);
                    com.Parameters.AddWithValue("@DIEUHOA", xeEntity.DIEUHOA);
                    com.Parameters.AddWithValue("@THIETBIGIAITRI", xeEntity.THIETBIGIAITRI);

                    com.Parameters.AddWithValue("@TUIKHIANTOAN", xeEntity.TUIKHIANTOAN);
                    com.Parameters.AddWithValue("@HETHONGBAOTROM", xeEntity.HETHONGBAOTROM);
                    com.Parameters.AddWithValue("@CHONGBOCUNGPHANH", xeEntity.CHONGBOCUNGPHANH);
                    com.Parameters.AddWithValue("@DIEUKHIENHANHTRINH", xeEntity.DIEUKHIENHANHTRINH);
                    com.Parameters.AddWithValue("@GIABAN", xeEntity.GIABAN);


                    com.Parameters.AddWithValue("@HINHANH", xeEntity.HINH);
                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
        public static DataSet GETDATATABLENONE(string ACTION)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("ACTION", ACTION);
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
        
        public static DataSet GET_ALLHANGXE(string ACTION)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("ACTION", ACTION);
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }

        public static DataSet GET_ALLXeByMAHANG(string ACTION,XE_ENTITY xeEntity)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@MAHANG", xeEntity.MAHANG);
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
        public static DataSet GET_TTXEBYMAXE(string ACTION, XE_ENTITY xeEntity)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@MAXE", xeEntity.MAXE);
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
        //=====================
        public static DataSet GETDATATABLE_MAHANGONLY(string ACTION, HANGXE_ENTITY hx)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet dt;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (hx != null)
                {
                    com.Parameters.AddWithValue("@MAHANG", hx.MAHANG);
                    com.Parameters.AddWithValue("@TENHANG", hx.TENHANG);
                    com.Parameters.AddWithValue("@QUOCGIA", hx.QUOCGIA);

                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                dt = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }

    }
